/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

/**
 * 文本消息推送
 */
import React, { useCallback } from "react";
import { connect } from "dva";
import { Modal, Row, Col, message } from "antd";
import AddInfo from "./components/AddInfo";

const MessagePush = props => {
  const { dispatch, platformList = {} } = props;
  const { weixin: { platform } = {} } = platformList;

  const handleOk = useCallback(
    (value, err, resetFields) => {
      if (err) return;
      if (!platform) {
        message.warn("暂无绑定的微信公众号平台，请先到”微信管理-设置”中新增关联！");
        return;
      }
      Modal.success({
        title: "温馨提示",
        content: "确定后，文本内容会推送给公众号48小时内访问的用户！",
        onOk: () => {
          dispatch({
            type: "massPush/insertText",
            payload: {
              platform,
              push_type: "text",
              push_info: value,
            },
          }).then(res => {
            message.success(res.msg);
            resetFields();
          });
        },
      });
    },
    [dispatch, platform]
  );

  return (
    <div>
      <Row type="flex" justify="space-between">
        <Col span={8} push={1}>
          <AddInfo
            onSubmit={(content, { err, resetFields }) => handleOk(content, err, resetFields)}
            contentTitle="推送文本内容"
          />
        </Col>
        <Col span={8} pull={1}>
          {/* <Input.TextArea rows="10" /> */}
        </Col>
      </Row>
      <Row style={{ marginTop: 40 }}>
        <Col style={{ fontWeight: "bolder", fontSize: "16px" }}>
          注：1、可以发送文本消息给公众号粉丝。2、文本消息内可展示文字或跳转H5/小程序链接。3、48小时内关注，发消息给公众号/点击过菜单的粉丝才能收到。
        </Col>
      </Row>
    </div>
  );
};

export default connect(({ platform }) => ({
  platformList: platform.platformList,
}))(MessagePush);
